package com.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.mapper.CategoryMapper;
import com.pojo.Category;
import com.service.CategoryService;
import com.util.Page;

@Service
public class CategoryServiceImpl implements CategoryService {

	@Autowired
	CategoryMapper categoryMapper;
	
	@Override
	public List<Category> list() {
		
		return categoryMapper.list();
	}

	@Override
	@Transactional(propagation = Propagation.REQUIRED,rollbackForClassName = "Exception")
	public void addTwo() {
		Category c = new Category();
		c.setName("可插入category");
		
		categoryMapper.add(c);
		
		c = new Category();
		c.setName("超过数据库长度，导致报错无法插入。超过数据库长度，导致报错无法插入。"
				+ "超过数据库长度，导致报错无法插入。超过数据库长度，导致报错无法插入。"
				+ "超过数据库长度，导致报错无法插入。超过数据库长度，导致报错无法插入。");
		categoryMapper.add(c);
	}

	@Override
	public void deleteAll() {
		
		List<Category> allCategory = list();
		for(Category c : allCategory) {
			
			categoryMapper.delete(c.getId());
		}
	}

//	@Override
//	public List<Category> list(Page page) {
//		
//		return categoryMapper.list(page);
//	}

//	@Override
//	public int count() {
//		
//		return categoryMapper.total();
//	}

}
